package cn.edu.nuc.ehelper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import cn.edu.nuc.dictFile.copy2SD;

public class EheplerActivity extends Activity {
	public static String DICT_PATH = "";
	private final String TAG = "EheplerActivity";
	private boolean DEBUG = true;
	private EditText queryEdit;
	private Button wordsBook;
	private Button review;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		DICT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()
				+ "/dict";
		copy2SD c2sd = new copy2SD(this);
		boolean flag;
			flag = c2sd.loadDictFile(DICT_PATH);
			if (flag && DEBUG) {
				Log.d(TAG, "loaddict succ!");
			} else {
				Log.d(TAG, "load Error");
			}

		queryEdit = (EditText) findViewById(R.id.queryEditTextId);
		wordsBook = (Button) findViewById(R.id.wordsBookButtonId);
		review = (Button) findViewById(R.id.reviewButtonId);

		wordsBook.setOnClickListener(new ButtonListener());
		review.setOnClickListener(new ButtonListener());

		queryEdit.addTextChangedListener(new TextWatcher() {

			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub
				System.out.println(s);
			}

			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub

			}
		});
	}

	class ButtonListener implements OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.wordsBookButtonId:
				Intent wordsBookIntent = new Intent(EheplerActivity.this,
						WordsBookActivity.class);
				startActivity(wordsBookIntent);
				break;
			case R.id.reviewButtonId:
				Intent reviewIntent = new Intent(EheplerActivity.this,
						ReviewActivity.class);
				startActivity(reviewIntent);
				break;
			default:
				break;
			}
		}

	}

}